package com.shilei.qr;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.awt.*;
import java.io.IOException;
import java.net.URLDecoder;
import java.net.URLEncoder;

@Controller
public class QrControl {

    @RequestMapping(value = "/getQr")
    @ResponseBody
    public void getImage(HttpServletRequest request, HttpServletResponse response ) throws IOException {
        String content = request.getParameter("content");
        String imgCode = request.getParameter("imgCode");
        String img="img/bixin.jpg";
        if (imgCode!=null){
            if ("xx1".equals(imgCode)){
                img="img/xx1.jpg";
            }else if("xx2".equals(imgCode)){
                img="img/xx2.jpg";
            }
        }

        System.out.println("1"+content);
//        content = URLDecoder.decode(content, "UTF-8");
        System.out.println("2"+content);
//        content = URLDecoder.decode(content, "UTF-8");
        System.out.println("3"+content);
        VisualQRCode.createQRCode(content, img, response, 'M', new Color(2, 85, 43), null, null, null, true,
                VisualQRCode.POSITION_DETECTION_SHAPE_MODEL_RECTANGLE, VisualQRCode.FILL_SHAPE_MODEL_CIRCLE);
        return;
    }


}

